/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.server.modules.sys.web.customer.impt;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.server.common.config.Global;
import com.server.common.persistence.Page;
import com.server.common.web.BaseController;
import com.server.common.utils.StringUtils;
import com.server.modules.sys.entity.customer.impt.CustomerImportLog;
import com.server.modules.sys.service.customer.impt.CustomerImportLogService;

/**
 * 客户导入日志Controller
 * @author 丁光彪
 * @version 2016-10-28
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/customer/impt/customerImportLog")
public class CustomerImportLogController extends BaseController {

	@Autowired
	private CustomerImportLogService customerImportLogService;
	
	@ModelAttribute
	public CustomerImportLog get(@RequestParam(required=false) String id) {
		CustomerImportLog entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = customerImportLogService.get(id);
		}
		if (entity == null){
			entity = new CustomerImportLog();
		}
		return entity;
	}
	
	//@RequiresPermissions("sys:customer:impt:customerImportLog:view")
	@RequestMapping(value = {"list", ""})
	public String list(CustomerImportLog customerImportLog, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CustomerImportLog> page = customerImportLogService.findPage(new Page<CustomerImportLog>(request, response), customerImportLog); 
		model.addAttribute("page", page);
		model.addAttribute("customerImportLog", customerImportLog);
		return "modules/sys/customer/impt/customerImportLogList";
	}

	//@RequiresPermissions("sys:customer:impt:customerImportLog:view")
	@RequestMapping(value = "form")
	public String form(CustomerImportLog customerImportLog, Model model) {
		model.addAttribute("customerImportLog", customerImportLog);
		return "modules/sys/customer/impt/customerImportLogForm";
	}

	//@RequiresPermissions("sys:customer:impt:customerImportLog:edit")
	@RequestMapping(value = "save")
	public String save(CustomerImportLog customerImportLog, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, customerImportLog)){
			return form(customerImportLog, model);
		}
		customerImportLogService.save(customerImportLog);
		addMessage(redirectAttributes, "保存客户导入日志成功");
		return "redirect:"+Global.getAdminPath()+"/sys/customer/impt/customerImportLog/?repage";
	}
	
	//@RequiresPermissions("sys:customer:impt:customerImportLog:edit")
	@RequestMapping(value = "delete")
	public String delete(CustomerImportLog customerImportLog, RedirectAttributes redirectAttributes) {
		customerImportLogService.delete(customerImportLog);
		addMessage(redirectAttributes, "删除客户导入日志成功");
		return "redirect:"+Global.getAdminPath()+"/sys/customer/impt/customerImportLog/?repage";
	}

}